<?php
require_once 'includes/auth.php';
require_once 'includes/config.php';
requireLogin();

$username = $_SESSION['username'];
$devInfo = getDeveloperInfo($username);
$isDev = ($devInfo !== null);
$apiCount = $isDev ? getAPICount($username) : 0;

$devDays = 0;
if ($isDev) {
    $regDate = new DateTime($devInfo['reg_time']);
    $now = new DateTime();
    $devDays = $now->diff($regDate)->days;
}
require_once 'track_online.php';
?>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>JIIL微聊开发者中心</title>
    <link rel="stylesheet" href="css/style.css">
    <style>
        .hero-section {
            background: linear-gradient(135deg, #2c3e50, #1a2a6c);
            padding: 80px 20px;
            text-align: center;
            color: white;
            position: relative;
            overflow: hidden;
        }
        
        .hero-section::before {
            content: '';
            position: absolute;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            background: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1440 320"><path fill="rgba(255,255,255,0.1)" d="M0,128L48,112C96,96,192,64,288,80C384,96,480,160,576,165.3C672,171,768,117,864,85.3C960,53,1056,43,1152,69.3C1248,96,1344,160,1392,192L1440,224L1440,320L1392,320C1344,320,1248,320,1152,320C1056,320,960,320,864,320C768,320,672,320,576,320C480,320,384,320,288,320C192,320,96,320,48,320L0,320Z"></path></svg>');
            background-size: cover;
            background-position: center bottom;
            opacity: 0.3;
        }
        
        .hero-section h1 {
            font-size: 3.5rem;
            margin-bottom: 20px;
            position: relative;
            z-index: 1;
        }
        
        .hero-section p {
            font-size: 1.5rem;
            max-width: 700px;
            margin: 0 auto 40px;
            position: relative;
            z-index: 1;
        }
        
        .cta-buttons {
            position: relative;
            z-index: 1;
        }
        
        .benefits-section {
            padding: 80px 0;
        }
        
        .section-title {
            text-align: center;
            margin-bottom: 50px;
            font-size: 2.5rem;
            color: #2c3e50;
        }
        
        .benefits-grid {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
            gap: 30px;
            max-width: 1200px;
            margin: 0 auto;
        }
        
        .benefit-card {
            background: white;
            border-radius: 10px;
            box-shadow: 0 5px 15px rgba(0,0,0,0.1);
            padding: 30px;
            text-align: center;
            transition: transform 0.3s ease;
        }
        
        .benefit-card:hover {
            transform: translateY(-10px);
        }
        
        .benefit-icon {
            font-size: 3.5rem;
            color: #3498db;
            margin-bottom: 20px;
        }
        
        .benefit-card h3 {
            font-size: 1.5rem;
            margin-bottom: 15px;
            color: #2c3e50;
        }
        
        .stats-section {
            padding: 80px 0;
            background: #f8f9fa;
        }
        
        .stats-container {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
            gap: 30px;
            max-width: 1200px;
            margin: 0 auto;
        }
        
        .stat-card {
            background: white;
            border-radius: 10px;
            box-shadow: 0 5px 15px rgba(0,0,0,0.1);
            padding: 30px;
            text-align: center;
        }
        
        .stat-number {
            font-size: 3rem;
            font-weight: bold;
            color: #3498db;
            margin-bottom: 10px;
        }
        
        .stat-title {
            font-size: 1.2rem;
            color: #6c757d;
        }
        
        .auth-card {
            background: white;
            border-radius: 10px;
            box-shadow: 0 5px 15px rgba(0,0,0,0.1);
            padding: 30px;
            max-width: 600px;
            margin: 40px auto;
            text-align: center;
        }
        
        .auth-card h3 {
            font-size: 1.8rem;
            margin-bottom: 20px;
            color: #2c3e50;
        }
        
        .auth-id-box {
            background: #f1f8fe;
            border-radius: 8px;
            padding: 20px;
            margin: 20px 0;
            font-family: monospace;
            word-break: break-all;
            font-size: 1.2rem;
            border-left: 4px solid #3498db;
        }
    </style>
</head>
<body>
    <header class="top-bar">
        <div class="logo">JIIL微聊开发平台</div>
        <nav class="nav-links">
            <a href="index.php" class="active">首页</a>
            <?php if ($isDev): ?>
                <a href="dev_console.php">控制台</a>
                <a href="dev_docs.php">文档</a>
            <?php else: ?>
                <a href="register_dev.php">成为开发者</a>
            <?php endif; ?>
            <a href="logout.php">退出</a>
        </nav>
    </header>
    
    <main>
        <section class="hero-section">
            <h1>JIIL微聊开发者平台</h1>
            <p>开启您的聊天自动化旅程，让机器人帮您完成重复工作</p>
            <div class="cta-buttons">
                <?php if (!$isDev): ?>
                    <a href="register_dev.php" class="btn btn-primary">成为开发者</a>
                <?php endif; ?>
                <a href="#features" class="btn btn-outline">了解更多</a>
            </div>
        </section>
        
        <section id="features" class="benefits-section">
            <h2 class="section-title">开发者专属特权</h2>
            <div class="benefits-grid">
                <div class="benefit-card">
                    <div class="benefit-icon">🤖</div>
                    <h3>自动化消息</h3>
                    <p>创建智能机器人，自动响应或发送消息，释放生产力</p>
                </div>
                <div class="benefit-card">
                    <div class="benefit-icon">📊</div>
                    <h3>详细数据统计</h3>
                    <p>实时监控API使用情况，了解每个机器人的活跃度</p>
                </div>
                <div class="benefit-card">
                    <div class="benefit-icon">🔧</div>
                    <h3>简易API集成</h3>
                    <p>只需几行代码即可快速接入，立即开始您的开发之旅</p>
                </div>
                <div class="benefit-card">
                    <div class="benefit-icon">🚀</div>
                    <h3>优先体验新功能</h3>
                    <p>第一时间获得新功能的体验权限，走在技术前沿</p>
                </div>
            </div>
        </section>
        
        <?php if ($isDev): ?>
            <section class="stats-section">
                <h2 class="section-title">您的开发者状态</h2>
                <div class="stats-container">
                    <div class="stat-card">
                        <div class="stat-number"><?= $apiCount ?></div>
                        <div class="stat-title">API调用次数</div>
                    </div>
                    <div class="stat-card">
                        <div class="stat-number"><?= $devDays ?></div>
                        <div class="stat-title">成为开发者天数</div>
                    </div>
                </div>
                
                <div class="auth-card">
                    <h3>您的专属鉴权ID</h3>
                    <div class="auth-id-box"><?= $devInfo['auth_id'] ?></div>
                    <p>使用此ID进行API调用认证</p>
                </div>
            </section>
        <?php endif; ?>
    </main>
    
    <footer class="footer">
        <p>© <?= date('Y') ?> JIIL微聊开发者平台 版权所有</p>
    </footer>
</body>
</html>